<template>
  <div>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['teacher:degree:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['teacher:degree:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['teacher:degree:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['teacher:degree:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getDegree"></right-toolbar>
    </el-row>

    <el-table border :data="degreeList" max-height="1000" @selection-change="handleSelectionChange" >
      <el-table-column type="selection" width="55" align="center" />
      <!--          <el-table-column label="主键" align="center" prop="recordid" />-->
<!--                <el-table-column label="教师ID" align="center" prop="a00" />-->
      <el-table-column fixed label="学历" align="center" prop="a0801" width="120"/>
      <el-table-column fixed label="学校" align="center" prop="a0806" width="120"/>
      <el-table-column fixed label="学制" align="center" prop="a0805"/>
      <el-table-column label="入学日期" align="center" prop="a0803" width="120">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.a0803, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="毕(肄)业日期" align="center" prop="a0804" width="120">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.a0804, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="从学单位类别" align="center" prop="a0808" width="120"/>
      <el-table-column label="所学专业名称" align="center" prop="a0809" width="120"/>
      <el-table-column label="学习完成情况" align="center" prop="a0811" width="120"/>
      <!--          <el-table-column label="学历级别" align="center" prop="a0814" />-->
      <el-table-column label="所学专业类别" align="center" prop="a0820" width="120"/>
      <el-table-column label="学位" align="center" prop="a0830" width="120"/>
      <!--          <el-table-column label="学位补充" align="center" prop="a0830a" />-->
      <!--          <el-table-column label="学位级别" align="center" prop="a0830c" />-->
      <el-table-column label="学位授予日期" align="center" prop="a0831" width="120">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.a0831, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="学位授予单位" align="center" prop="a0832" width="120"/>
      <el-table-column label="教育类别" align="center" prop="a0837" width="120"/>
      <el-table-column label="第二学位" align="center" prop="a0838" width="120"/>
      <el-table-column label="第二学位所学专业类别" align="center" prop="a0840" width="150"/>
      <el-table-column label=" 第二学位所学专业" align="center" prop="zdyxa0841" width="150"/>
      <el-table-column fixed="right" label="附件" align="center" prop="remark"  width="200">
        <template slot-scope="{row}">
          <el-link :href="row.remark" target="_blank" class="buttonText"  type="primary" :underline="false">{{row.remark}}</el-link>
        </template>
      </el-table-column>
      <el-table-column fixed="right" label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-info"
            @click="handleDetail(scope.row)"
          >详情</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['teacher:degree:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['teacher:degree:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getDegree"
    />

    <!-- 添加或修改学历学位信息对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="600px" append-to-body>
      <el-form v-bind:disabled="disabled" label-position="top" ref="form" :model="form" :rules="rules">
        <el-row gutter="15">
          <el-col :span="12">
            <el-form-item label="本人编号" prop="a00">
              <el-input v-model="form.a00" placeholder="请输入本人编号" clearable :style="{width: '100%'}"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label-width="200px" label="学历" prop="a0801">
              <el-select v-model="form.a0801" placeholder="请选择学历" clearable :style="{width: '100%'}">
                <el-option
                  v-for="dict in a0801Options"
                  :key="dict.dictValue"
                  :label="dict.dictLabel"
                  :value="dict.dictValue"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row gutter="15">
          <el-col :span="12">
            <el-form-item label="入学日期" prop="a0803">
              <el-date-picker clearable
                              v-model="form.a0803"
                              type="date"
                              value-format="yyyy-MM-dd"
                              placeholder="选择入学日期">
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="毕(肄)业日期" prop="a0804" >
              <el-date-picker clearable
                              v-model="form.a0804"
                              type="date"
                              value-format="yyyy-MM-dd"
                              placeholder="选择毕(肄)业日期">
              </el-date-picker>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row gutter="15">
          <el-col :span="12">
            <el-form-item label="学制" prop="a0805">
              <el-input v-model="form.a0805" placeholder="请输入学制" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="学校" prop="a0806">
              <el-input v-model="form.a0806" placeholder="请输入学校" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row gutter="15">
          <el-col :span="12">
            <el-form-item label="从学单位类别" prop="a0808">
              <el-input v-model="form.a0808" placeholder="请输入从学单位类别" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="所学专业名称" prop="a0809">
              <el-input v-model="form.a0809" placeholder="请输入所学专业名称" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row gutter="15">
          <el-col :span="12">
            <el-form-item label="学习完成情况" prop="a0811">
              <el-select v-model="form.a0811" placeholder="请选择学习完成情况">
                <el-option
                  v-for="dict in a0811Options"
                  :key="dict.dictValue"
                  :label="dict.dictLabel"
                  :value="dict.dictValue"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="学历级别" prop="a0814">
              <el-input v-model="form.a0814" placeholder="请输入学历级别" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row gutter="15">
          <el-col :span="12">
            <el-form-item label="所学专业类别" prop="a0820">
              <el-select v-model="form.a0820" placeholder="请选择所学专业类别">
                <el-option
                  v-for="dict in a0820Options"
                  :key="dict.dictValue"
                  :label="dict.dictLabel"
                  :value="dict.dictValue"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="学位" prop="a0830">
              <el-select v-model="form.a0830" placeholder="请选择学位">
                <el-option
                  v-for="dict in a0830Options"
                  :key="dict.dictValue"
                  :label="dict.dictLabel"
                  :value="dict.dictValue"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row gutter="15">
          <el-col :span="12">
            <el-form-item label="学位补充" prop="a0830a">
              <el-input v-model="form.a0830a" placeholder="请输入学位补充" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="学位级别" prop="a0830c">
              <el-input v-model="form.a0830c" placeholder="请输入学位级别" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row gutter="15">
          <el-col :span="12">
            <el-form-item label="学位授予日期" prop="a0831">
              <el-date-picker clearable size="small"
                              v-model="form.a0831"
                              type="date"
                              value-format="yyyy-MM-dd"
                              placeholder="选择学位授予日期">
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="学位授予单位" prop="a0832">
              <el-input v-model="form.a0832" placeholder="请输入学位授予单位" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row gutter="15">
          <el-col :span="12">
            <el-form-item label="教育类别" prop="a0837">
              <el-input v-model="form.a0837" placeholder="请输入教育类别" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="第二学位" prop="a0838">
              <el-input v-model="form.a0838" placeholder="请输入第二学位" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row gutter="15">
          <el-col :span="12">
            <el-form-item label="第二学位所学专业类别" prop="a0840">
              <el-select v-model="form.a0840" placeholder="请选择第二学位所学专业类别">
                <el-option
                  v-for="dict in a0840Options"
                  :key="dict.dictValue"
                  :label="dict.dictLabel"
                  :value="dict.dictValue"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label=" 第二学位所学专业" prop="zdyxa0841">
              <el-input v-model="form.zdyxa0841" placeholder="请输入 第二学位所学专业" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row gutter="15">
<!--          <el-col :span="12">-->
<!--            <el-form-item label="删除标识" prop="delFlag">-->
<!--              <el-input v-model="form.delFlag" placeholder="请输入删除标识" />-->
<!--            </el-form-item>-->
<!--          </el-col>-->
        </el-row>
        <el-form-item label="附件" prop="remark">
          <fileUpload v-model="form.remark"/>
        </el-form-item>
      </el-form>
      <div v-show="!hidden" slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listDegree, getDegree, delDegree, addDegree, updateDegree, exportDegree } from "@/api/teacher/degree";
import {selectDegreeByA00} from "@/api/teacher/person";
import FileUpload from "@/components/FileUpload";

export default {
  name: "Degree",
  components: {
    FileUpload
  },
  data() {
    return {
      hidden: false,
      //禁用状态
      disabled: false,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 学历学位信息表格数据
      degreeList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 学历字典
      a0801Options: [],
      // 学习完成情况字典
      a0811Options: [],
      // 所学专业类别字典
      a0820Options: [],
      // 学位字典
      a0830Options: [],
      // 教育类别字典
      a0837Options: [],
      // 第二学位所学专业类别字典
      a0840Options: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        a00: null,
        a0801: null,
        a0830: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getDegree();
    this.getDicts("sys_person_education").then(response => {
      this.a0801Options = response.data;
    });
    this.getDicts("sys_person_study").then(response => {
      this.a0811Options = response.data;
    });
    this.getDicts("sys_person_professionType").then(response => {
      this.a0820Options = response.data;
    });
    this.getDicts("sys_person_degree").then(response => {
      this.a0830Options = response.data;
    });
    this.getDicts("sys_person_educationMethod").then(response => {
      this.a0837Options = response.data;
    });
    this.getDicts("sys_person_professionType").then(response => {
      this.a0840Options = response.data;
    });
  },
  methods: {
    //获取教育背景
    getDegree() {
      this.A00 = this.$route.query.A00
      selectDegreeByA00(this.A00).then((response) => {
        this.degreeList = response.rows;
      });
    },
    // 学历字典翻译
    a0801Format(row, column) {
      return this.selectDictLabel(this.a0801Options, row.a0801);
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        recordid: null,
        a00: null,
        a0801: null,
        a0803: null,
        a0804: null,
        a0805: null,
        a0806: null,
        a0808: null,
        a0809: null,
        a0811: null,
        a0814: null,
        a0820: null,
        a0830: null,
        a0830a: null,
        a0830c: null,
        a0831: null,
        a0832: null,
        a0837: null,
        a0838: null,
        a0840: null,
        zdyxa0841: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        delFlag: null,
        remark: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getDegree();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.recordid)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加学历学位信息";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.disabled = false
      this.hidden = false;
      this.reset();
      const recordid = row.recordid || this.ids
      getDegree(recordid).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改学历学位信息";
      });
    },
    /** 详情按钮操作 */
    handleDetail(row) {
      this.hidden = true;
      this.disabled = true;
      this.reset();
      const recordid = row.recordid || this.ids
      getDegree(recordid).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "学历学位信息详情";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.recordid != null) {
            updateDegree(this.form).then(response => {
              this.msgSuccess("修改成功");
              this.open = false;
              this.getDegree();
            });
          } else {
            addDegree(this.form).then(response => {
              this.msgSuccess("新增成功");
              this.open = false;
              this.getDegree();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const recordids = row.recordid || this.ids;
      this.$confirm('是否确认删除学历学位信息编号为"' + recordids + '"的数据项?', "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(function() {
        return delDegree(recordids);
      }).then(() => {
        this.getDegree();
        this.msgSuccess("删除成功");
      })
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出所有学历学位信息数据项?', "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(function() {
        return exportDegree(queryParams);
      }).then(response => {
        this.download(response.msg);
      })
    }
  }
};
</script>
